# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=openocd
pkgver=0.12.0
pkgrel=5
pkgdesc="Free and Open On-Chip Debugging, In-System Programming and Boundary-Scan Testing"
url="https://openocd.org/"
arch="all"
license="GPL-2.0-only,GPL-2.0-or-later,GPL-3.0-only"
makedepends="libftdi1-dev libusb-dev hidapi-dev jimtcl-dev libjaylink-dev
	automake autoconf libtool"
subpackages="$pkgname-dev $pkgname-doc $pkgname-udev-rules:udev_rules"
source="https://downloads.sourceforge.net/project/openocd/openocd/$pkgver/openocd-$pkgver.tar.bz2
	fix-jimtcl-link.patch"
builddir="$srcdir/$pkgname-$pkgver"

provides="openocd-virtual"
provider_priority=20

prepare() {
	default_prepare
	update_config_sub
	libtoolize -f
	aclocal
	automake --add-missing
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-werror \
		--enable-cmsis-dap \
		--enable-sysfsgpio \
		--enable-bcm2835gpio \
		--disable-internal-jimtcl \
		--disable-internal-libjaylink
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 contrib/60-openocd.rules \
		"$pkgdir"/usr/lib/udev/rules.d/60-$pkgname.rules
}

udev_rules() {
	pkgdesc="udev rules for $pkgname"
	amove usr/lib/udev/rules.d/60-$pkgname.rules
}

sha512sums="
b32a8b9fe81ad23d8a544284f4bc626ca302e498dae95399a2f36756407dd1a63e8e9655ca1084e7cc13cf1b932d8f6a480f470a4c3ad502cd884ec7508738e9  openocd-0.12.0.tar.bz2
6fd2fbe11917bb7f181ba67812f63e75d51bcd19e4df6a7e22e1abb8f36a4f4bdc9202e815f560476ec184d54d84df8ae4dceb17f2429b9dc1d9503804dacb03  fix-jimtcl-link.patch
"
